/*
 * CommuRoute.c
 *
 *  Created on: 2025-4-30
 *      Author: Andy.zhai
 */
#include "Commu.h"
#include "CommuRoute.h"
#include "CommuApi.h"

uint8_t SendToMCU(uint8_t *data, uint32_t len);
uint8_t SendToUART(uint8_t *data, uint32_t len);
uint8_t SendToSPI(uint8_t *data, uint32_t len);
uint8_t SendToSDIO(uint8_t *data, uint32_t len);

static commu_func_handle_t dispatch_handle[TID_MAX_NUM] = {
        {TID_MCU, SendToMCU},
        {TID_UART, SendToUART},
        {TID_SPI, SendToSPI},
        {TID_SDIO, SendToSDIO},
};

void route_data(uint8_t *data, uint32_t len)
{
    rt_kprintf("[Commu]:recv CMD:%02x%02x%02x tick:%d\n", data[0], data[2], data[3], rt_tick_get());
    uint8_t tid = data[0] & 0x0F;

    for (uint8_t i = TID_MCU;i < TID_MAX_NUM;i++) {
        if (dispatch_handle[i].id == tid) {
            if (dispatch_handle[i].handleMessage(data, len) != 0) {
                rt_kprintf("[Commu]:message dispatch fail\n");
            }
            return;
        }
    }
    rt_kprintf("[Commu]:unknow messgae\n");
}
